<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>IntPtr</title>
    <link rel="stylesheet" href="../../CSS/css_initialize.css" />
    <link rel="stylesheet" href="../../CSS/css_common.css" />
  </head>
  <body>
    <div class="flex-row">
      <div class="sidebar">
        <ol class="sidebar-content">
          <li class="sidebar-item-h1"><a href="#Title">IntPtr</a></li>
          <li class="sidebar-item-h1"><a href="#Dfinition">定义</a></li>
          <li class="sidebar-item-h1"><a href="#Instruction">说明</a></li>
          <li class="sidebar-item-h1"><a href="#Constructor">构造函数</a></li>
          <li class="sidebar-item-h1"><a href="#Field">字段</a></li>
          <li>
            <ol>
              <li class="sidebar-item-h2"><a href="#Field01">Zero</a></li>
            </ol>
          </li>
          <li class="sidebar-item-h1"><a href="#Property">属性</a></li>
          <li>
            <ol>
              <li class="sidebar-item-h2"><a href="#Property01">MinValue</a></li>
              <li class="sidebar-item-h2"><a href="#Property02">MaxValue</a></li>
              <li class="sidebar-item-h2"><a href="#Property03">Size</a></li>
            </ol>
          </li>
          <li>
          <li class="sidebar-item-h1"><a href="#Method">方法</a></li>
          <li>
            <ol>
              <li class="sidebar-item-h2"><a href="#Method01">Parse</a></li>
              <li class="sidebar-item-h2"><a href="#Method02">TryParse</a></li>
              <li class="sidebar-item-h2"><a href="#Method03">Add</a></li>
              <li class="sidebar-item-h2"><a href="#Method04">Subtract</a></li>
              <li class="sidebar-item-h2"><a href="#Method05">DivRem</a></li>
              <li class="sidebar-item-h2"><a href="#Method06">Log2</a></li>
              <li class="sidebar-item-h2"><a href="#Method07">Abs</a></li>
              <li class="sidebar-item-h2"><a href="#Method08">Clamp</a></li>
              <li class="sidebar-item-h2"><a href="#Method09">Min</a></li>
              <li class="sidebar-item-h2"><a href="#Method10">MinMagnitude</a></li>
              <li class="sidebar-item-h2"><a href="#Method11">Max</a></li>
              <li class="sidebar-item-h2"><a href="#Method12">MaxMagnitude</a></li>
              <li class="sidebar-item-h2"><a href="#Method13">LeadingZeroCount</a></li>
              <li class="sidebar-item-h2"><a href="#Method14">TrailingZeroCount</a></li>
              <li class="sidebar-item-h2"><a href="#Method15">PopCount</a></li>
              <li class="sidebar-item-h2"><a href="#Method16">RotateLeft</a></li>
              <li class="sidebar-item-h2"><a href="#Method17">RotateRight</a></li>
              <li class="sidebar-item-h2"><a href="#Method18">Sign</a></li>
              <li class="sidebar-item-h2"><a href="#Method19">CopySign</a></li>
              <li class="sidebar-item-h2"><a href="#Method20">IsEvenInteger</a></li>
              <li class="sidebar-item-h2"><a href="#Method21">IsOddInteger</a></li>
              <li class="sidebar-item-h2"><a href="#Method22">IsPositive</a></li>
              <li class="sidebar-item-h2"><a href="#Method23">IsNegative</a></li>
              <li class="sidebar-item-h2"><a href="#Method24">IsPow2</a></li>
              <li class="sidebar-item-h2"><a href="#Method25">CreateChecked</a></li>
              <li class="sidebar-item-h2"><a href="#Method26">CreateSaturating</a></li>
              <li class="sidebar-item-h2"><a href="#Method27">CreateTruncating</a></li>
              <li class="sidebar-item-h2"><a href="#Method28">CompareTo</a></li>
              <li class="sidebar-item-h2"><a href="#Method29">Equals</a></li>
              <li class="sidebar-item-h2"><a href="#Method30">ToString</a></li>
              <li class="sidebar-item-h2"><a href="#Method31">ToPointer</a></li>
              <li class="sidebar-item-h2"><a href="#Method32">ToInt32</a></li>
              <li class="sidebar-item-h2"><a href="#Method33">ToInt64</a></li>
              <li class="sidebar-item-h2"><a href="#Method34">TryFormat</a></li>
            </ol>
          </li>
          <li class="sidebar-item-h1"><a href="#Override">重写</a></li>
          <li>
            <ol>
              <li class="sidebar-item-h2"><a href="./001001Object.html#Method04">GetHashCode</a></li>
            </ol>
          </li>
        </ol>
      </div>
      <div class="content">
        <header>
          <h1 id="Title">IntPtr</h1>
          <nav class="head-nav"><a class="fl" href="./001015UIntPtr.html">上一篇</a><a class="fr" href="./001017Single.html">下一篇</a></nav>
        </header>
        <section>
          <h2 id="Dfinition">定义</h2>
          <div class="block-code">
            <p>C#</p>
            <pre>public readonly struct IntPtr</pre>
          </div>
          <p>命名空间：<a href="../System.html">System</a></p>
          <p>程序集：System.Runtime.dll</p>
          <p><span class="tag struct-tag">结构体</span><span class="tag readonly-tag">只读</span></p>
        </section>
        <section>
          <h2 id="Instruction">说明</h2>
          <p><span class="inline-code">IntPtr</span>表示与指针相同位宽的带符号整数，即在32位系统上为32位，在64位系统上为64位，默认值为0。</p>
        </section>
        <section>
          <h2 id="Constructor">构造函数</h2>
          <div class="block-code">
            <p>C#</p>
            <pre>public IntPtr(int value)
public IntPtr(long value)
public IntPtr(void* value)</pre>
          </div>
          <p>初始化<span class="inline-code">IntPtr</span>实例。</p>
        </section>
        <section>
          <h2 id="Field">字段</h2>
          <h3 id="Field01">Zero</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static readonly IntPtr Zero;</pre>
          </div>
          <p><span class="tag static-tag">静态</span><span class="tag readonly-tag">只读</span></p>
          <p><span class="inline-code">IntPtr</span>类型的值0。</p>
        </section>
        <section>
          <h2 id="Property">属性</h2>
          <h3 id="Property01">MinValue</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr MinValue { get; }</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p><span class="inline-code">IntPtr</span>类型的最小值。</p>
          <h3 id="Property02">MaxValue</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr MaxValue { get; }</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p><span class="inline-code">IntPtr</span>类型的最大值。</p>
          <h3 id="Property03">Size</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static int Size { get; }</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p><span class="inline-code">IntPtr</span>的尺寸，单位字节。</p>
        </section>
        <section>
          <h2 id="Method">方法</h2>
          <h3 id="Method01">Parse</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr Parse(string s)
public static IntPtr Parse(string s, IFormatProvider? provider)
public static IntPtr Parse(string s, System.Globalization.NumberStyles style)
public static IntPtr Parse(string s, System.Globalization.NumberStyles style, IFormatProvider? provider)
public static IntPtr Parse(ReadOnlySpan<char> s, IFormatProvider? provider)
public static IntPtr Parse(ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default)
public static IntPtr Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider)
public static IntPtr Parse(ReadOnlySpan<byte> utf8Text, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>将字符串（前面和后面可以有空格）转化为<span class="inline-code">IntPtr</span>，转换失败时会抛出异常。</p>
          <h3 id="Method02">TryParse</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static bool TryParse(string s, out IntPtr result)
public static bool TryParse(string s, IFormatProvider? provider, out IntPtr resul)
public static bool TryParse(string s, System.Globalization.NumberStyles style, IFormatProvider? provider, out IntPtr resul)
public static bool TryParse(ReadOnlySpan<char> s, out IntPtr result)
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out IntPtr resul)
public static bool TryParse(ReadOnlySpan<char> s, System.Globalization.NumberStyles style, IFormatProvider? provider, out IntPtr resul)
public static bool TryParse(ReadOnlySpan<byte> utf8Text, out IntPtr result)
public static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out IntPtr resul)
public static bool TryParse(ReadOnlySpan<byte> utf8Text, System.Globalization.NumberStyles style, IFormatProvider? provider, out IntPtr resul)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>与<span class="inline-code">Parse</span>方法类型，将字符串（前面和后面可以有空格）转化为<span class="inline-code">IntPtr</span>，但不会抛出异常。</p>
          <h3 id="Method03">Add</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr Add(IntPtr pointer, int offset)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取指定指针加上指定偏移量后指向的数。</p>
          <h3 id="Method04">Subtract</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr Subtract(IntPtr pointer, int offset)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取指定指针减去指定偏移量后指向的数。</p>
          <h3 id="Method05">DivRem</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static (IntPtr Quotient, IntPtr Remainder) DivRem(IntPtr left, IntPtr right)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取左数除以右数的商和余数。</p>
          <h3 id="Method06">Log2</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr Log2(IntPtr value)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取指定对象的Log2。</p>
          <h3 id="Method07">Abs</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr Abs(IntPtr value)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取指定对象的绝对值。</p>
          <h3 id="Method08">Clamp</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr Clamp(IntPtr value, IntPtr min, IntPtr max)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>将指定对象钳制到指定的最小值（可及）和最大值之间（可及）。</p>
          <h3 id="Method09">Min</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr Min(IntPtr x, IntPtr y)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取二者中较小的。</p>
          <h3 id="Method10">MinMagnitude</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr MinMagnitude(IntPtr x, IntPtr y)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取二者中较小的。</p>
          <h3 id="Method11">Max</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr Max(IntPtr x, IntPtr y)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取二者中较大的。</p>
          <h3 id="Method12">MaxMagnitude</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr MaxMagnitude(IntPtr x, IntPtr y)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取二者中较大的。</p>
          <h3 id="Method13">LeadingZeroCount</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr LeadingZeroCount(IntPtr value)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取指定对象的前导0数量。</p>
          <h3 id="Method14">TrailingZeroCount</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr TrailingZeroCount(IntPtr value)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取指定对象的后置0数量。</p>
          <h3 id="Method15">PopCount</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr PopCount(IntPtr value)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取指定对象的位数。</p>
          <h3 id="Method16">RotateLeft</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr RotateLeft(IntPtr value, int rotateAmount)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>将指定对象向左旋转指定位数。</p>
          <h3 id="Method17">RotateRight</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr RotateRight(IntPtr value, int rotateAmount)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>将指定对象向右旋转指定位数。</p>
          <h3 id="Method18">Sign</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static int Sign(IntPtr value)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>获取指定对象的符号。</p>
          <h3 id="Method19">CopySign</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr CopySign(IntPtr value, IntPtr sign)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>返回一个值，此值的数值和符号分别来自两个参数。</p>
          <h3 id="Method20">IsEvenInteger</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static bool IsEvenInteger(IntPtr value)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>判断指定对象是否为偶数。</p>
          <h3 id="Method21">IsOddInteger</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static bool IsOddInteger(IntPtr value)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>判断指定对象是否为奇数。</p>
          <h3 id="Method22">IsPositive</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static bool IsPositive(IntPtr value)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>判断指定对象是否为正数。</p>
          <h3 id="Method23">IsNegative</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static bool IsNegative(IntPtr value)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>判断指定对象是否为负数。</p>
          <h3 id="Method24">IsPow2</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static bool IsPow2(IntPtr value)</pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>判断指定对象是否为2的幂。</p>
          <h3 id="Method25">CreateChecked</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr CreateChecked<TOther>(TOther value) where TOther : System.Numerics.INumberBase<TOther></pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>根据参数创建一个<span class="inline-code">IntPtr</span>实例，溢出时会抛出异常。</p>
          <h3 id="Method26">CreateSaturating</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr CreateSaturating<TOther>(TOther value) where TOther : System.Numerics.INumberBase<TOther></pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>根据参数创建一个<span class="inline-code">IntPtr</span>实例，溢出时使用饱和算法进行范围限制。</p>
          <h3 id="Method27">CreateTruncating</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public static IntPtr CreateTruncating<TOther>(TOther value) where TOther : System.Numerics.INumberBase<TOther></pre>
          </div>
          <p><span class="tag static-tag">静态</span></p>
          <p>根据参数创建一个<span class="inline-code">IntPtr</span>实例，溢出时使用截断算法进行范围限制。</p>
          <h3 id="Method28">CompareTo</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public int CompareTo(IntPtr value)
public int CompareTo(object? value)</pre>
          </div>
          <p>比较当前实例与指定对象，并返回一个表明二者关系的整数：大于0表示当前实例大于指定对象，小于0则相反，等于0表示二者相等。需要注意的是，<span class="inline-code">CompareTo(Object)</span>的参数需要是<span class="inline-code">IntPtr</span>类型或<span class="inline-code">null</span>，否则将会抛出异常。</p>
          <p>因为不需要拆箱，<span class="inline-code">CompareTo(IntPtr)</span>比<span class="inline-code">CompareTo(Object)</span>的性能更好。</p>
          <h3 id="Method29">Equals</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public bool Equals(IntPtr obj)
public override bool Equals(object? obj)</pre>
          </div>
          <p><span class="tag override-tag">重写</span></p>
          <p>判断当前实例与指定对象是否相等。</p>
          <p>因为不需要拆箱，<span class="inline-code">Equals(IntPtr)</span>比< class="inline-code">Equals(Object)</  span>的性能更好。</p>
          <h3 id="Method30">ToString</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public override string ToString()
public override string ToString(string? format)
public string ToString(IFormatProvider? provider)
public override string ToString(string? format, IFormatProvider? provider)</pre>
          </div>
          <p><span class="tag override-tag">重写</span></p>
          <p>将当前实例转化为字符串。</p>
          <h3 id="Method31">ToPointer</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public void* ToPointer()</pre>
          </div>
          <p>将当前实例转化为指向未指定类型的指针。</p>
          <h3 id="Method32">ToInt32</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public int ToInt32()</pre>
          </div>
          <p>将当前实例转化为<span class="inline-code">Int32</span>。</p>
          <h3 id="Method33">ToInt64</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public long ToInt64()</pre>
          </div>
          <p>将当前实例转化为<span class="inline-code">Int64</span>。</p>
          <h3 id="Method34">TryFormat</h3>
          <div class="block-code">
            <p>C#</p>
            <pre>public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = default)
public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = default)</pre>
          </div>
          <p>尝试将当前实例的值的格式设置为提供的字符范围。</p>
        </section>
        <footer>
          <nav class="foot-nav"><a class="fl" href="./001015UIntPtr.html">上一篇</a><a class="fr" href="./001017Single.html">下一篇</a></nav>
        </footer>
      </div>
    </div>
  </body>
</html>
